package RedBook;

import common.ListNode;

import java.util.*;

/**
 * @author zhangmin
 * @create 2022-09-25 15:51
 * 计算每个节点到各个节点之间的最短路径，然后以每个点为M去找最短路径
 */
public class Main_0925_3 {

    static int[] dijkstra(int start,List<int[]>[] graph,boolean[] visited){
        int n = graph.length;
        int[] distTo=new int[n];
        Arrays.fill(distTo,Integer.MAX_VALUE);
        distTo[start]=0;
        for (int i = 1; i < n; i++) {
            int u=-1;
            int min=Integer.MAX_VALUE;
            for (int j = 1; j < n; j++) {
                if (!visited[j]&&distTo[j]<min){
                    u=j;
                    min=distTo[j];
                }
            }
            if (u==-1) return distTo;
            visited[u]=true;
            for (int[] edge:graph[u]) {
                int v=edge[0];
                int w=edge[1];
                if (!visited[v]&&distTo[u]+w<distTo[v]){
                    distTo[v]=distTo[u]+w;
                }
            }
        }
        return distTo;
    }
    public static void main(String[] args) {
        Scanner cin=new Scanner(System.in);
        int n=cin.nextInt();
        int[] edge=new int[n];
        for (int i = 1; i < n; i++) {
            edge[i]=cin.nextInt();
        }
        int[] power=new int[n];
        for (int i = 1; i < n; i++) {
            power[i]=cin.nextInt();
        }
        int A=cin.nextInt(),B=cin.nextInt(),C=cin.nextInt();
        List<int[]>[] graph=new LinkedList[n+1];
        for (int i = 1; i <=n ; i++) {
            graph[i]=new LinkedList<>();
        }
        //构造图
        for (int i = 1; i < n; i++) {
            int node1=i+1;
            int node2=edge[i];
            graph[node1].add(new int[]{node2,power[i]});
            graph[node2].add(new int[]{node1,power[i]});
        }
        long res=Integer.MAX_VALUE;
        //用地杰斯特拉求出从每个节点出发到达三个点的距离
        for (int i = 1; i <= n; i++) {
            boolean[] visited=new boolean[n+1];
            Arrays.fill(visited,false);
            int[] dijkstra = dijkstra(i, graph,visited);
            long sum=dijkstra[A]+dijkstra[B]+dijkstra[C];
            res=Math.min(res,sum);
        }
        System.out.println(res);
    }
}
